<?php

namespace App\Http\Controllers;


use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Services\CallServices;
use App\Http\Services\ConfigServices;
use Illuminate\Http\Request;


//打call
class CallController extends Controller
{
    private $call_services;
    private $config_services;


    public function __construct()
    {
        $this->call_services = new CallServices();
        $this->config_services = new ConfigServices();
    }

    //合成打call
    public function payCall(Request $request)
    {
        $user_id = $request->input('user_id', 0);
        if (intval($user_id) == 0) OutJson::toJson(-1, '失败');
        $num = $request->input('num', 1);
        $res = $this->call_services->payCall($user_id, $num);
        OutJson::toJson($res['code'], $res['msg'], $res['data']);
    }


//    //普通开奖
//    public function awardMall(Request $request)
//    {
//        $user_id = $request->input('user_id', 0);
//        if (intval($user_id) == 0) OutJson::toJson(-1, '失败');
//        $res = $this->call_services->awardMall($user_id);
//        OutJson::toJson($res['code'], $res['msg'], $res['data']);
//    }

    //加速开奖
    public function speedAward(Request $request)
    {
        $user_id = $request->input('user_id', 0);
        if (intval($user_id) == 0) OutJson::toJson(-1, '失败');
        $res = $this->call_services->diamondSpeed($user_id);
        OutJson::toJson($res['code'], $res['msg'], $res['data']);
    }

    //获取基础信息
    public function getCallUserInfo(Request $request)
    {
        $user_id = $request->input('user_id', 0);
        if (intval($user_id) == 0) OutJson::toJson(-1, '获取用户信息失败');
        $res = $this->call_services->getCallUserInfo($user_id);
        OutJson::toJson($res['code'], $res['msg'], $res['data']);
    }

    //中奖纪录
    public function getLog(Request $request)
    {
        $user_id = $request->input('user_id', 0);
        $res = $this->call_services->getLog($user_id);
        OutJson::toJson(0, '成功', $res);
    }

    //定时任务发送系统消息
    public function getUserSendMsg(Request $request)
    {
        $res = $this->call_services->getUserSendMsg();
        OutJson::toJson(0, '成功', $res);
    }

    public function checkDate()
    {
        $check_date = $this->config_services->checkConfigDate(29, time(), 'call_date');
        if (!$check_date) {
            write_log('dishTimeOut', 'timeError', []);
            OutJson::toJson(3001, '活动时间错误', []);
        }
    }

}